package com.jhgsys.internal.formDesign.controller.app;

import com.jhgsys.internal.common.annotation.Log;
import com.jhgsys.internal.common.entity.FebsResponse;
import com.jhgsys.internal.common.exception.FebsException;
import com.jhgsys.internal.formDesign.dto.FormDesignDto;
import com.jhgsys.internal.formDesign.entity.FormFill;
import com.jhgsys.internal.formDesign.service.IFormDesignService;
import com.jhgsys.internal.formDesign.service.IFormFillService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * 表单设计 移动端Controller
 *
 * @author fenghaijun
 * @date 2024-08-28 10:54:00
 */
@Slf4j
@Validated
@Controller
public class FormDesignApiController {

    @Autowired
    private IFormDesignService formDesignService;

    @Autowired
    private IFormFillService formFillService;
    /**
     * 修改是否设为模板
     * @param formFill
     * @return
     * @throws FebsException
     */
    @PostMapping("app/formDesign/view")
    @ResponseBody
    public FebsResponse findFormFill(@RequestBody FormFill formFill) throws FebsException {
        try {
            FormDesignDto formDesign = formDesignService.findFormDesignById(formFill.getDesignId());
            FormFill formFillS = formFillService.findFormFillById(formFill.getRegisterId());
            Map<String,Object> formMap = new HashMap<>();
            formMap.put("formDesign",formDesign);
            formMap.put("formFill",formFillS);
            return new FebsResponse().success().data(formMap);
        } catch (Exception e) {
            String message = "获取表单失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }
}
